package edu.uwm.capstone.util;

public final class StringUtil {
	public static String clip(String paramString, int paramInt) {
		if (paramInt <= paramString.length())
			return paramString.substring(0, paramInt);
		return paramString;
	}

	public static boolean equalsIgnoreCase(String paramString1,
			String paramString2) {
		if (paramString1 == paramString2)
			return true;
		if ((paramString1 == null) || (paramString2 == null))
			return false;
		return paramString1.equalsIgnoreCase(paramString2);
	}

	public static boolean isDigit(CharSequence paramCharSequence) {
		for (int i = 0;; i++) {
			if (i >= paramCharSequence.length())
				return true;
			if (!Character.isDigit(paramCharSequence.charAt(i)))
				return false;
		}
	}

	public static boolean isEmpty(CharSequence paramCharSequence) {
		return (paramCharSequence == null) || ("".equals(paramCharSequence));
	}

	public static boolean isEqual(String paramString1, String paramString2) {
		return ObjectUtil.isEqual(paramString1, paramString2);
	}

	public static boolean isLetter(String paramString) {
		for (int i = 0;; i++) {
			if (i >= paramString.length())
				return true;
			if (!Character.isLetter(paramString.charAt(i)))
				return false;
		}
	}

	public static boolean isWhitespace(CharSequence paramCharSequence) {
		for (int i = 0;; i++) {
			if (i >= paramCharSequence.length())
				return true;
			if (!Character.isWhitespace(paramCharSequence.charAt(i)))
				return false;
		}
	}

	public static String padLeft(String paramString, int paramInt) {
		return padLeft(paramString, paramInt, ' ');
	}

	public static String padLeft(String paramString, int paramInt,
			char paramChar) {
		if (paramString.length() < paramInt)
			return replicateChar(paramChar, paramInt - paramString.length())
					+ paramString;
		return paramString;
	}

	public static String padRight(String paramString, int paramInt) {
		return padRight(paramString, paramInt, ' ');
	}

	public static String padRight(String paramString, int paramInt,
			char paramChar) {
		if (paramString.length() < paramInt)
			return paramString
					+ replicateChar(paramChar, paramInt - paramString.length());
		return paramString;
	}
	
	/*May be have to define replace function*/

	public static String replicateChar(char paramChar, int paramInt) {
		char[] arrayOfChar = new char[paramInt];
		for (int i = 0;; i++) {
			if (i >= paramInt)
				return new String(arrayOfChar);
			arrayOfChar[i] = paramChar;
		}
	}

	public static String trimLeft(String paramString) {
		final int totalLength = paramString.length();
		int i;
		for (i = 0; i < totalLength
				&& Character.isWhitespace(paramString.charAt(i)); i++) {
			//increment i;
		}
		if (i == 0) {
			return paramString;
		} else {
			return paramString.substring(i);
		}
	}

	public static String trimRight(String paramString) {
		int totalLength = paramString.length() - 1;
		int i;
		for (i = totalLength; Character.isWhitespace(paramString.charAt(i)); i--) {
			// Decrement i;
		}
		if (i < totalLength)
			return paramString.substring(0, i + 1);
		else
			return paramString;

	}

}
